package main

import "fmt"

//切片：定义给定长度是数组，未指定是切片
//创建：a.make make([]string, 11) b.直接创建[]string{}
//引用传递
func main() {
	//数组
	var arrayStr = [10]string{}
	arrayStr[0] = "123"

	//定义切片
	var sliceStr = []string{"0", "1", "2", "3", "4", "5", "6", "7", "8"}
	sliceStr[0] = "456"

	sliceStr = make([]string, 11)
	sliceStr[9] = "000"

	println("数组", arrayStr[0], "切片", sliceStr[0])

	//应用传递
	testSlice2(sliceStr)
	//循环切片
	for _, vSlice := range sliceStr {
		println("循环切片", vSlice)
	}

	//从索引位置5开始存值,容量为10
	mySlice := make([]int, 5, 10)
	mySlice = append(mySlice, 1)
	fmt.Println("mySlice= ", mySlice)
	//从索引位置0开始存值
	mySlice2 := make([]int, 0)
	mySlice2 = append(mySlice2, 1)
	fmt.Println("mySlice2= ", mySlice2)

	//合并两个切片
	a := [5]int{1, 2, 3, 4, 5}
	s := a[1:3] // s := a[low:high]
	s = append(s, 10, 1, 2, 3, 6, 7, 8, 9, 9, 9, 76, 4, 3, 4, 5, 6, 5, 5, 5)
	fmt.Printf("s:%v len(s):%v cap(s):%v\n", s, len(s), cap(s))

	s2 := append(s, s...)
	fmt.Printf("s:%v len(s):%v cap(s):%v\n", s2, len(s2), cap(s2))

}

func testSlice2(param []string) {
	param[0] = "哈哈哈"
}
